﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace comm.lib
{
    [Serializable]
    public enum ObjEVType
    {
        MAP_OBJ = 0,
        DOBJ = 1
    }

    [Serializable]
    public class ObjEVDefine
    {
        public static T FindEV<T>(Dictionary<string, ObjEV> evDic)
        {
            var key = "";
            return FindEV<T>(evDic, out key);
        }
        public static T FindEV<T>(Dictionary<string, ObjEV> evDic, out string key)
        {
            foreach (var evKey in evDic.Keys)
            {
                if (evDic[evKey].Value is T)
                {
                    key = evKey;
                    return (T)(object)evDic[evKey].Value;
                }
            }
            key = null;
            return default(T);
        }

        public const string METHOD_NAME = "GetObjEVDefineDic";

        public ObjEVDefine(Type type, object value, string version)
        {
            Type = type;
            Value = value;
            Version = version;
        }

        public ObjEVDefine(Type type, object value)
        {
            Type = type;
            Value = value;
        }

        public Type Type { get; set; }
        public object Value { get; set; }

        private string _version = null;
        public string Version
        {
            get
            {
                if (_version == null)
                {
                    _version = "1";
                }
                return _version;
            }
            set { _version = value; }
        }
    }

    [Serializable]
    public class ObjEV
    {
        public object Value { get; set; }
        public string Version { get; set; }
    }
}
